<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('留言')" />
    <th:block th:include="include :: datetimepicker-css" />
    <link th:href="@{/css/picker.css}" rel="stylesheet"/>

</head>

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="ly">

            <input th:type="hidden" th:value="${session.name}" name="xingming">
            <input th:type="hidden" th:value="${session.phone}" name="shoujihao">
            <div class="form-group">
                <label class="col-sm-3 control-label">留言：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <textarea style="height: 200px;" name="neirong" class="form-control" type="text" ></textarea>
                </div>
            </div>

           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">姓名：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <input name="xingming" class="form-control" type="text" >
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">手机号：<span style="color: red;">*</span></label>
                <div class="col-sm-8">
                    <input name="shoujihao" class="form-control" type="text">
                </div>
            </div>-->

            <div class="form-group">
                <div class="col-sm-12" style="text-align:center;">
                    <a class="btn btn-primary btn-rounded btn-lg" onclick="add()"><i class="fa fa-plus"></i>留言</a>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12" style="text-align:center;">
                    <a class="btn btn-warning btn-rounded btn-lg" href="/system/yuyue/index">返回</a>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:src="@{/js/picker.js}"></script>

    <script th:inline="javascript">

        var prefix = ctx + "system/liuyan"

        function add() {

            var liuyan = new Object();

            liuyan.neirong = $("textarea[name='neirong']").val();
            liuyan.xingming = $("input[name='xingming']").val();
            liuyan.shoujihao = $("input[name='shoujihao']").val();


            if(!liuyan.neirong){
                alert("请填写留言内容！");
                return false;
            }
          /*  if(!liuyan.xingming){
                alert("请填写姓名！");
                return false;
            }
            if(!liuyan.shoujihao){
                alert("请填写手机号！");
                return false;
            }else{
                let pattern = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
                if(!pattern.test(liuyan.shoujihao)){
                    alert("手机号填写错误");
                    return false;
                }
            }*/

            $.ajax({
                type: "post",
                url:  prefix+"/add",
                data: {
                    "neirong":liuyan.neirong,
                    "xingming":liuyan.xingming,
                    "shoujihao":liuyan.shoujihao,
                },
                success: function(r) {
                    if (r.code == 0) {
                        if (confirm("提交成功")) {
                            location.href = '/system/yuyue/index';
                        }
                    } else {
                        alert(r.msg);
                    }
                }
            });
        }

    </script>
</body>
</html>